package com.mobileares.midp.widgets.client.menu;

import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.user.client.ui.*;
import com.mobileares.midp.widgets.client.panel.EventFlowPanel;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2011-3-18
 * Time: 10:16:54
 * To change this template use File | Settings | File Templates.
 */
public class BaseMenuItem extends Composite {
    private EventFlowPanel item;
    private SimplePanel imagePanel;
    private Label textPanel;

    public BaseMenuItem(String text, String imageUrl) {
        item = new EventFlowPanel();
        item.setStyleName("menu-item");
        imagePanel = new SimplePanel();
        if (imageUrl != null) {
            Image image = new Image(imageUrl);
            image.setVisibleRect(0, 0, 10, 10);
            imagePanel.add(image);
        }
        imagePanel.setStyleName("image");
        textPanel = new Label(text);
        textPanel.setStyleName("text");


        item.add(imagePanel);
        item.add(textPanel);
        initWidget(item);
        initEvent();
    }

    public BaseMenuItem(String text) {
        this(text, null);
    }

    private void initEvent(){
        item.addMouseOverHandler(new MouseOverHandler() {
            public void onMouseOver(MouseOverEvent event) {
                item.addStyleName("menu-item-over");
            }
        });
        item.addMouseOutHandler(new MouseOutHandler() {
            public void onMouseOut(MouseOutEvent event) {
              item.removeStyleName("menu-item-over");
            }
        });
    }

}
